package za.ac.wits.elen7045.persistence.datasource.sqlite;

import java.sql.ResultSet;
import java.sql.SQLException;
import za.ac.wits.elen7045.persistence.datasource.DataSourceRowEntry;
import za.ac.wits.elen7045.persistence.model.User;
import za.ac.wits.elen7045.persistence.util.UserTableConstants;

public class UserSQLiteDataSource extends SQLiteDataSource<User> implements UserTableConstants {

	@Override
	protected User parseCurrentRowToObject(ResultSet resultSet) throws SQLException {
		User user = new User();
		user.setId(resultSet.getInt(USER_ID));
		user.setName(resultSet.getString(USER_NAME));
		user.setUsername(resultSet.getString(USER_USERNAME));
		user.setPassword(resultSet.getString(USER_LATEST_PASSWORD));
		return user;
	}

	@Override
	protected DataSourceRowEntry parseObjectToDataSourceRowEntry(User user) throws SQLException {
		DataSourceRowEntry entry = new DataSourceRowEntry();
		entry.setValue(USER_ID, user.getId());
		entry.setValue(USER_NAME, user.getName());
		entry.setValue(USER_USERNAME, user.getUsername());
		entry.setValue(USER_LATEST_PASSWORD, user.getPassword());
		return entry;
	}

}
